package com.hins.demo.convertor;

import com.hins.demo.dao.dataobject.AccountDO;
import com.hins.demo.model.transfer.entity.Account;
import com.hins.demo.model.transfer.valueobject.*;
import org.springframework.stereotype.Component;

/**
 * Description: 666
 *
 * @author wenjiaqi
 * @date 2021/5/14 19:19
 */
@Component
public class AccountConvertor {
    public Account toAccount(AccountDO accountDO) {
        return new Account(
                new AccountId(accountDO.getAccountId()),
                new AccountNumber(accountDO.getAccountNumber()),
                new UserId(accountDO.getUserId()),
                new Money(accountDO.getAvailable(), new Currency(accountDO.getCurrency())),
                new Money(accountDO.getDailyLimit(), new Currency(accountDO.getCurrency())),
                new Currency(accountDO.getCurrency()));
    }

    public AccountDO toAccountDO(Account account) {
        AccountDO accountDO = new AccountDO();
        accountDO.setAccountId(account.getAccountId().getValue());
        accountDO.setAccountNumber(account.getAccountNumber().getValue());
        accountDO.setUserId(account.getUserId().getValue());
        accountDO.setAvailable(account.getAvailable().getAmount());
        accountDO.setDailyLimit(account.getDailyLimit().getAmount());
        accountDO.setCurrency(accountDO.getCurrency());
        return accountDO;
    }
}
